#include<bits/stdc++.h>
using namespace std;
int t,d[100005],v[100005];
int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	cin>>t;
	while(t--)
	{
		int n,m,L,V;
		int ans=0;
		cin>>n>>m>>L>>V;
		for(int i=1;i<=n;i++)
		{
			int p;
			cin>>d[i]>>v[i]>>p;
			
		}
		int max_=-111111111;
		for(int i=1;i<=m;i++)
		{
			int _;
			cin>>_;
			if(_>max_) max_=_;
		}
		for(int i=1;i<=n;i++)
			if(d[i]<=max_&&d[i]<=L&&v[i]>V) ans++;
		if(ans==0) m++;
		cout<<ans<<" "<<m-1<<endl;
		
	}
	return 0;
}
